package com.jinhongone.beans.factory.support;

import com.jinhongone.beans.factory.config.BeanDefinition;
import com.jinhongone.beans.factory.support.BeanDefinitionRegistry;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author jinho
 * @className SimgleBeanDefinitionRegistry
 * @description BeanDefinitionRegistry的简单实现
 * @date 2025/4/25 16:31
 */
public class SimgleBeanDefinitionRegistry implements BeanDefinitionRegistry {

    //用来存放beanDefition的容器，不是bean容器，而是xml解析后的beanDefition容器。
    private Map<String, BeanDefinition> map = new ConcurrentHashMap<>();

    @Override
    public void registryBeanDefinition(String beanName, BeanDefinition bd) {
        map.put(beanName, bd);
    }

    @Override
    public void removeBeanDefinitionByName(String beanName) {
        map.remove(beanName);
    }

    @Override
    public BeanDefinition getBeanDefinitionByName(String beanName) {
        return map.get(beanName);
    }

    @Override
    public boolean containByName(String beanName) {
        return map.containsKey(beanName);
    }

    @Override
    public int getBeanDefinitionCount() {
        return map.size();
    }

    @Override
    public String[] getBeanDefintionNames() {
        return map.keySet().toArray(new String[0]);
    }
}
